
public class CommonLogic
{
    // Converts a Long into a byte array
    public static byte[] LongToBytes(long n)
    {
	byte[] b = new byte[8];
	b[7] = (byte) (n);
	n >>>= 8;
	b[6] = (byte) (n);
	n >>>= 8;
	b[5] = (byte) (n);
	n >>>= 8;
	b[4] = (byte) (n);
	n >>>= 8;
	b[3] = (byte) (n);
	n >>>= 8;
	b[2] = (byte) (n);
	n >>>= 8;
	b[1] = (byte) (n);
	n >>>= 8;
	b[0] = (byte) (n);

	return b;
    }
    
    // Converts a byte array into a Long
    public static long BytesToLong(byte[] b, int o)
    {
	long val = 0;
	for ( int i=0; i<8; i++ )
	{ 
	    int shift = 7-i;
	    val |= (b[o+i]<<shift);
	}
	return val;
    }    
}
